﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Special_Item
{
    public partial class Pro_User_Login : Form
    {
        public Pro_User_Login()
        {
            InitializeComponent();
        }

        private void btn_zc_Click(object sender, EventArgs e)
        {
            Pro_Admin_Increase increase = new Pro_Admin_Increase();
            increase.Show();
            this.Hide();
        }

        private void btn_Login_Click(object sender, EventArgs e)
        {
            
            if (string.IsNullOrWhiteSpace(this.txt_User.Text))
            {
                MessageBox.Show("用户名不能为空！", "提示信息", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
                this.txt_User.Focus();
            }
            else if (string.IsNullOrWhiteSpace(this.txt_Pwd.Text))
            {
                MessageBox.Show("密码不能为空！", "提示信息", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
                this.txt_Pwd.Focus();
            }else if(this.txt_Pwd.Text.Length<5)
            {
                MessageBox.Show("密码长度不能小于5位！", "提示信息", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
                this.txt_Pwd.Focus();
            }
            else
            {
                //数据库连接判断有没有用户
//                var stu = @"Data Source=.;
//                      Initial Catalog=Training_Project;
//                      Uid=zc;
//                      Pwd=1234;";
//                var conn = new SqlConnection(stu);
//                try
//                {
//                    conn.Open();
                  var abc = this.cob_Login.Text;
                    if (abc == "学生登录")
                    {
                        //var sql = string.Format("select UserName from Stu_Login where UserName='{0}'",this.txt_User.Text);
                        //SqlCommand comm = new SqlCommand(sql, conn);
                        //object obj = comm.ExecuteScalar();
                        //var sql1 = string.Format("select Passward from Stu_Login where UserName='{0}'", this.txt_User.Text);
                        //SqlCommand comm1 = new SqlCommand(sql1, conn);
                        //object obj1 = comm1.ExecuteScalar();
                        //if (!this.txt_User.Text.Equals(obj))
                        //{
                        //    MessageBox.Show("没有此用户，请注册！", "提示信息", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
                        //    this.txt_User.Focus();
                        //}
                        //else if (!this.txt_Pwd.Text.Equals(obj1))
                        //{
                        //    MessageBox.Show("你输入的密码有误，请从新输入！", "提示信息", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
                        //    this.txt_Pwd.Focus();
                        //}
                        //else
                        //{
                            Pro_User_Index form = new Pro_User_Index();
                            form.Show();
                            this.Hide();
                       // }
                    }
                    else if (abc == "管理员登录")
                    {
                        //var Sql = string.Format("select UserName from Manager_Login where UserName='{0}'", this.txt_User.Text);
                        //SqlCommand Comm = new SqlCommand(Sql, conn);
                        //object Obj = Comm.ExecuteScalar();
                        //var Sql1 = string.Format("select Passward from Manager_Login where UserName='{0}'", this.txt_User.Text);
                        //SqlCommand Comm1 = new SqlCommand(Sql1, conn);
                        //object Obj1 = Comm1.ExecuteScalar();
                        //if (!this.txt_User.Text.Equals(Obj))
                        //{
                        //    MessageBox.Show("没有此管理员，请注册！", "提示信息", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
                        //    this.txt_User.Focus();
                        //}
                        //else if (!this.txt_Pwd.Text.Equals(Obj1))
                        //{
                        //    MessageBox.Show("你输入的密码有误，请从新输入！", "提示信息", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
                        //    this.txt_Pwd.Focus();
                        //}
                        //else
                        //{
                            Pro_Admin_Index form = new Pro_Admin_Index();
                            form.Show();
                            this.Hide();
                       // }
                    }
                    else
                    {
                        MessageBox.Show("请选择登录类型！", "提示信息", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
                    }
                    
                    
                //}
                //catch (Exception)
                //{

                //}
                //finally
                //{
                //    conn.Close();
                //}

            }
        }
       
    }
}
